package com.cskaoyan.catmall.service.Impl;

import com.cskaoyan.catmall.dao.MarketBrandMapper;
import com.cskaoyan.catmall.model.bo.BaseParamBo;
import com.cskaoyan.catmall.model.vo.BrandDetailWxVO;
import com.cskaoyan.catmall.model.vo.BrandListDataWxVo;
import com.cskaoyan.catmall.model.vo.BrandListWxVo;
import com.cskaoyan.catmall.service.BrandServiceWx;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @date: 2022-01-09-21-13
 * @author: ZYY
 * @description: 品牌的实现接口
 */
@Service
public class BrandServiceImpWx implements BrandServiceWx {


    @Autowired
    MarketBrandMapper brandMapper;



    @Override
    public BrandListWxVo brandList(BaseParamBo params) {
        Integer limit = params.getLimit();  // 获得每页的最大数量
        Integer page = params.getPage();  // 获得页码
        // 使用PageHelper
        // 开启分页功能，传入页码和数据量
        PageHelper.startPage(page,limit);

        // 查询数据库
        List<BrandListDataWxVo> list = brandMapper.selectWx();

        //获得PageHelper封装到PageInfo中的数据
        PageInfo<BrandListDataWxVo> pageInfo = new PageInfo<>(list);
        int pages = pageInfo.getPages();
        long total = pageInfo.getTotal();

        BrandListWxVo data = BrandListWxVo.data(total, pages, limit, page, list);
        return data;
    }

    @Override
    public BrandDetailWxVO brandDetail(Integer id) {
        BrandDetailWxVO data = brandMapper.selectById(id);
        return data;
    }
}